package com.huaxia.day11;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapTest {
    public static void main(String[] args) {
//        Map<String, Student> map = create();
//        print(map);
        nullTest();
    }

    public static Map<String, Student> create() {
        Map<String, Student> studentMap = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            studentMap.put("name_" + i, new Student("name_" + i, (int) (Math.random() * 100)));
        }
        System.out.println(studentMap.size());
        return studentMap;
    }

    /**
     * @param map map 的多种循环，获取keys,获取entry
     *            map 中根据value获得key？
     */
    public static void print(Map<String, Student> map) {
        Set<String> keys = map.keySet();
        for (String s : keys) {
            System.out.println(String.format("key:{%s},value:{%s}", s, map.get(s).toString()));
        }

        for (Map.Entry<String, Student> entry : map.entrySet()) {
            System.out.println(String.format("key:%s,value:%s", entry.getKey(), entry.getValue().toString()));
        }

        Iterator<Map.Entry<String, Student>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Student> entry = iterator.next();
            System.out.println(String.format("key:%s,value:%s", entry.getKey(), entry.getValue().toString()));
        }
    }

    public static void nullTest(){
        Map<String,String> map = new HashMap<>();
        map.put("a","er");
        map.put(null,"23");
        map.put("c",null);
        map.put("d",null);
        map.put(null,null);
        System.out.println(map.get(null));

    }
}
